<template>

  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">

            <!-- 放置表单 -->
            <el-form label-width="120px" style="margin-left: 120px; margin-top:30px" :model="formdata" :rules="rules">
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="formdata.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:" prop="newpassword">
                <el-input v-model="formdata.newpassword" style="width:300px" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="upuser">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <userinfo />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <jobinfo />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>

</template>
<script>
import { userPic, upuser } from '@/api/user'
import jobinfo from './components/jobinfo.vue'
import userinfo from './components/userinfo.vue'
export default {
  components: {
    jobinfo, userinfo
  },
  data() {
    return {
      formdata: {
        username: '',
        newpassword: ''
      },
      rules: {
        username: [{ required: true, message: '该项不能为空', trigger: 'blur' }],
        newpassword: [{ required: true, message: '该项不能为空', trigger: 'blur' }]
      }
    }
  },
  async created() {
    this.formdata = await userPic(this.$route.params.id)
    // this.formdata.newpassword = 123456
  },
  methods: {
    async upuser() {
      const res = await upuser({ ...this.formdata, password: this.formdata.newpassword })
      this.$message.success('修改成功')

      console.log(res)
    }
  }
}
</script>
